<div class="content" id="orders">
    <script type="text/x-dot-template" id="addrInfoTemp">
        {{~it.result:value:index}}
        <div class="box-panel address" id="{{=value[0]}}">
            <div><p class="left title">申请时间:<span class="addTime" data-val="{{=value[7]}}"></span></p>
                <p class="right title orderState" style="color: #ffc786" data-val='{{=value[3]}}'></p></div>
            <hr>
            <div class="text"><span>报修故障：</span><span>{{=value[1]}}&nbsp;&nbsp;{{=value[13]}}&nbsp;&nbsp;{{=value[2]}}</span></div>
            <div class="text"><span>预约地址：</span><span>{{=value[6]}}</span></div>
            {{?value[3]<2}}
            <div><p class="but" onclick="cancelRepairOrder('{{=value[0]}}')">取消报修</p></div>
            {{?}}
        </div>
        {{~}}
    </script>
</div>


<div class="ypfood-head">
    <div class="back-div" onClick="javascript :history.back(-1);">
        <img src="/statics/imgs/head-back.png?v=${params.ver}">
    </div>
    <div>
        <span class="title-span">报修记录</span>
    </div>
</div>
<script>
    json("/repair/orderList.json", {}, function (data) {
        if (data.code == 0) {
            $("#orders").html(doT.template($("#addrInfoTemp").html())(data));
            var c = eval(data.state);
            var d = new Dictionary(c);
            $(function () {
                $.each($('p.orderState'), function (index, item) {
                    var s = $(item).attr('data-val');
                    $(item).html(d.get(s));
                });
                $.each($('span.addTime'), function (index, item) {
                    var s = $(item).attr('data-val');
                    if (s != undefined) {
//                $(item).html(format(new Date(s), "yyyy-MM-dd HH:mm:ss"));
                        $(item).html(s.substr(0,19));
                    }
                });
            });
            function Dictionary(map) {
                this.data = map;
                this.get = function (key) {
                    return this.data[key];
                };
                this.size = function () {
                    var i = 0;
                    for (var j in this.data) {
                        i++;
                    }
                    return i;
                }
                this.setMapData = function (map) {
                    this.data = map;
                }
                this.setListData = function (list) {
                    for (var i = 0; i < list.length; i++) {
                        this.data.i = list[i];
                    }
                }
                this.toString = function () {
                    var str = '{';
                    for (var i in this.data) {
                        str += i + ':' + this.data[i] + ', ';
                    }
                    str += '}';
                    return str;
                }

            }

            function format(time, format) {
                var t = new Date(time);
                var tf = function (i) {
                    return (i < 10 ? '0' : '') + i
                };
                return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
                    switch (a) {
                        case 'yyyy':
                            return tf(t.getFullYear());
                            break;
                        case 'MM':
                            return tf(t.getMonth() + 1);
                            break;
                        case 'mm':
                            return tf(t.getMinutes());
                            break;
                        case 'dd':
                            return tf(t.getDate());
                            break;
                        case 'HH':
                            return tf(t.getHours());
                            break;
                        case 'ss':
                            return tf(t.getSeconds());
                            break;
                    }
                })
            }

        }
    });
    function cancelRepairOrder(id){
        var url = '/admin/repair/cancelOrder.jspa';
        json(url, {id: id}, function (data) {
            if (data.code == 0) {
                $("#"+id+" .orderState").html("已取消");
                $("#"+id+" .but").css("display","none");
            } else {
                alert(data.description);
            }
        });
    }
</script>
